Timers & Script Run Commands
|
There are cases when executed code
requires delay before continuing to
the next step (line of code). Either
it's about moving to another page,
delaying execution of current script
or another script, time & script
run commands serve as creators of
pauses / delays.
Strange thing to do, indeed.
In reality we try to avoid delays and
here we make artificial ones.
You'll use commands like Pause and
ScriptTimer to delay execution of
scripts either for data processing
purposes or waiting for some event
like user input. There are two
specific timer-related commands - with
PageTimer you set delay before moving
to some other project page, and with
ExitTimer command MMB waits specified
amount of time before it exits the
project.
RunScript command won't make any
delays - it will immediately run
specified script.
Both ScriptTimer and RunScript don't
interrupt running of current script
when calling another one - ScriptTimer
will immediately continue with code
lines of it's current script,
RunScript will wait for called script
to finish and then continue with code
lines (if any) below.
All timer-related commands use
millisecond as a time unit. One second
contains 1000 milliseconds, and you'll
often use n x 1000 to manage
delays in seconds.
|
|
|
|
Delays
further
running
of
current
script
for
specified
amount
of
time.
|
|
|
|
|
**Pause
script
for
5
seconds
(5000
ms)
:
Pause("5000")
**
Pause
script
for
12
seconds
(12000
ms)
using
numerical
variable:
delay=12000
Pause("delay")
|
|
|
|
|
This
command
is
occasionally
being
used
to
make
delay
for
user
input
or
wait
for
some
external
task
(like
data
processing,
copying)
to
finish.
|
|
|
|
|
|
Runs
script
specified
as
command
parameter.
|
|
|
|
|
**Run
script
labeled
"Calculate"
:
RunScript("Calculate")
|
|
|
|
|
Running
of
other
scripts
saves
you
from
re-writing
code
lines
-
it's
recommended
to
put
frequently
used
routines
under
separate
script
objects
and
run
'em
whenever
they're
needed.
Code
lines
below
RunScript
line
will
in
most
cases
wait
for
called
script
to
finish
it's
work,
so
put
and
retrieve
processing
results
using
string
and
numerical
variables.
This
command
runs
default
(Mouse
Up)
script
on
objects
with
both
Mouse
Down
and
Mouse
Up
events
(Buttons,
Bitmaps,
Rectangles,
etc).
WARNING!
Do not use RunScript
command to call
the same Script
object/MouseUp event multiple
times and from the
same Script object!
This will cause
an infinite recursion,
because RunScript
wait for its end.
After using RunScript
in that type of
code you can see
"Recursion
in Script reached
50 levels"
error message. You
can use ScriptTimer
instead, which doesn't
wait for end.
|
|
|
ScriptTimer("ObjectLabel","ms")
|
|
|
|
Waits
for
specified
amount
of
time
(number
or
numerical
variable
as
second
parameter)
and
then
starts
execution
of
another
script,
specified
as
first
command
parameter:
ScriptTimer("ScriptLabel","TimeDelay")
To
give
you
extra
power,
MMB
introduces
3
independent
timers
inside
ScriptTimer
command,
called
TimerA,
TimerB
and
TimerC.
Using
this
principle,
you
can
call
ScriptTimer
command
3
times,
using
different
timers
(A,B,C)
and
make
3
independent
threads
-
every
thread
runs
it's
own
script
and
won't
care
much
about
others.
Using
these
timers
starts
by
writing
their
labels...
TimerA,
TimerB
or
TimerC
...together
with
equal
sign
as
a
script
label
prefix:
ScriptTimer("TimerA=ScriptLabel1","TimeDelay")
ScriptTimer("TimerB=ScriptLabel2","TimeDelay")
ScriptTimer("TimerC=ScriptLabel3","TimeDelay")
|
|
|
|
|
**
Run
Script1
with
delay
of
8
seconds
:
ScriptTimer("Script1","8000")
**
Run
MyScript
with
delay
specified
using
numerical
variable
:
delay=5500
ScriptTimer("Script1","delay")
**
Run
ThreadScript
with
5
second
delay
and
using
TimerA:
ScriptTimer("TimerA=ThreadScript","5000")
|
|
|
|
|
This
command
is
occasionally
being
used
to
make
delay
for
user
input
or
wait
for
some
external
task
(like
data
processing,
copying)
to
finish.
ScriptTimer
runs
script
only
once,
so
you
have
to
call
ScriptTimer
command
again
to
repeat
script
running.
In
addition
to
this,
running
of
ScriptTimer
before
previously
set
timer
delay
has
elapsed
will
reset
previous
setting
and
use
the
new
one.
For
example,
if
you
run:
ScriptTimer("Script1","8000")
...and
before
elapsed
8
seconds
you
call
ScriptTimer
again:
ScriptTimer("Script2","12000")
...previous
setting
will
be
substituted
with
the
new
one,
running
Script2
after
12
seconds.
This
is
also
the
case
for
individual
timers
A,B
and
C.
ScriptTimer
command
runs
default
(Mouse
Up)
script
on
objects
with
both
Mouse
Down
and
Mouse
Up
events
(Buttons,
Bitmaps,
Rectangles,
etc).
All
running scripts (including
ScriptTimers) running
from ordinary Page
are terminated by
jump to another
Page. If you want
to preserve run
of a ScripTimer
even if user jumps
between pages, place
the Script object
on Master Page/Layer
and then call it
with Master
Page::
or Master
Layer::
prefix (as described
here).
Then
the script should
appear like this: ScriptTimer("Master
Page::Script","100") or
this if you want
to use multiple
timers. ScriptTimer("TIMERA=Master
Page::Script","100")
|
|
|
PageTimer("ms","PageLabel")
|
|
|
|
Waits
for
specified
amount
of
time
(number
or
numerical
variable
as
the
first
parameter)
and
then
either
moves
to
the
next
page
(if
second
parameter
is
empty),
page
specified
as
the
second
parameter,
or
performs
one
of
the
following
actions
specified
as
the
second
command
parameter:
THIS_PAGE
-
restarts
current
project
page
(object
positions,
background
music)
and
runs
it's
startup
script
THIS_SCRIPT
-
runs
only
startup
script
of
current
project
page
IF_IDLE
-
moves
to
next
page
if
there's
no
keyboard
or
mouse
click
event
for
specified
amount
of
time
|
|
|
|
|
**
Move
to
next
page
after
8
seconds:
PageTimer("8000","")
**Move
to
Page
7
after
20
seconds
:
PageTimer("20000","Page
7")
**Run
startup
script
of
current
page
after
10
seconds
:
PageTimer("10000","THIS_SCRIPT")
**Restart
current
page
after
5
seconds
:
PageTimer("5000","THIS_PAGE")
**Move
to
next
page
if
no
user
interaction
for
60
seconds
:
PageTimer("60000","IF_IDLE")
|
|
|
|
|
Running
of
PageTimer
before
previously
set
timer
delay
has
elapsed
will
reset
previous
setting
and
use
the
new
one.
For
example,
if
you
run:
PageTimer("120000","")
...and
before
elapsed
120
seconds
you
call
PageTimer
again:
PageTimer("180000","")
...previous
setting
will
be
substituted
with
the
new
one
and
timer
will
move
to
next
page
after
180
seconds.
Using
ExitTimer
after
PageTimer
will
cancel
PageTimer
event.
|
|
|
|
|
|
Waits
for
specified
amount
of
time
(number
or
numerical
variable
as
command
parameter)
and
then
exits
(closes)
project.
If
keyboard
or
mouse
click
event
occurs
during
delay,
ExitTimer
is
cancelled.
|
|
|
|
|
**Exit
from
project
after
120
seconds
of
user
inactivity:
PageTimer("120000")
|
|
|
|
|
Running
of
PageTimer
before
ExitTimer
delay
has
elapsed
will
cancel
ExitTimer
event.
For
example,
if
you
run:
ExitTimer("120000","")
...and
before
elapsed
120
seconds
you
call
PageTimer:
PageTimer("12000","")
...PageTimer
will
cancel
ExitTimer
event.
|
|
|
|
|
|
Redraws
project's
window
and
allows
processing
of
other
events
in
project
(mouse
&
keyboard
input,
running
of
scripts,
etc).
|
|
|
|
|
**
Perform
refresh
Refresh()
|
|
|
|
|
Calling
this
command
is
highly
recommended
in
for..next
loops,
to
allow
processing
of
other
threads
(running
routines
also
present
in
project)
and
avoid
'freezing'
of
application
window.
|
|
|
|
MMB Scripting Unleashed by
Bokzy, 2003
:: All rights reserved ::
http://www.bokzy.com
|